﻿@model planerka.DataAccess.ViewModels.UserAdministration.IndexViewModel

@{ ViewBag.Title = "Управление пользователями"; }

    <h2>Управление пользователями</h2>
@using (Html.BeginForm("refreshFilter", "UserAdministration"))
{   
    
        List <SelectListItem> sl = new List<SelectListItem>();
        sl.Add(new SelectListItem{ Text= "-- все роли", Value = "", Selected = ("" == Model.roleFilter)});  
        foreach (var item in Model.Roles)
	    {
		    sl.Add(new SelectListItem{ Text= item, Value = item, Selected = (item == Model.roleFilter)});  
	    }    
  <text>
    @Html.DropDownList("roleFilter", sl)
    &nbsp;&nbsp;&nbsp;логин:
    @Html.TextBox("loginFilter")
    &nbsp;&nbsp; 
    <input id="refreshFilter" type="submit" value="Обновить список" />
    </text>
    }
    <div class="mvcMembership-allUsers">
    @if(Model.Users.Count > 0){ 
		<div class="users">
            <fieldset style="background-color: #CCCCCC">
                <div class="username">
                <b><strong>
                Пользователь
                </strong></b>
                </div>
            
            <div class="email"><b><strong>email</strong></b></div>
            <div class="isOnOff"><b><strong>Режим</strong></b></div>
            <div class="roles"><b><strong>Роли</strong></b></div>
            <div class="comment"><b><strong>Комментарий</strong></b></div>
            
            </fieldset>
			@foreach (var user in Model.Users)
   { 
			<fieldset>
				<div class="username">
                @Html.ActionLink(user.UserName, "Details", new { id = user.ProviderUserKey })
                </div>
				<div class="email"><a href="mailto:@user.Email">@user.Email</a></div>
				@if (user.IsOnline)
    { 
					<div class="isOnline">Online</div>
    }
    else
    { 
					<div class="isOffline">Offline for
						@{
        string ret = "";
        var offlineSince = (DateTime.Now - user.LastActivityDate);
        if (offlineSince.TotalSeconds <= 60) { ret = ("1 minute."); }
        else if (offlineSince.TotalMinutes < 60) { ret = (Math.Floor(offlineSince.TotalMinutes) + " minutes."); }
        else if (offlineSince.TotalMinutes < 120) { ret = ("1 hour."); }
        else if (offlineSince.TotalHours < 24) { ret = (Math.Floor(offlineSince.TotalHours) + " hours."); }
        else if (offlineSince.TotalHours < 48) { ret = ("1 day."); }
        else { ret = (Math.Floor(offlineSince.TotalDays) + " days."); }
						}
                        @ret
					</div>
    } 
    @{ string userRoles = planerka.Web.Controllers.UserAdministrationController.getRolesByUser(user); }
                 <div class="roles">@userRoles</div>
                 <div class="comment">@if (!string.IsNullOrEmpty(user.Comment)) {
                 <text>
                    @user.Comment 
                 </text>
                 }</div>

                 
			</fieldset>
			 } 
		</div>
		<ul class="paging">

			@if (Model.Users.IsFirstPage){ 
			<li>First</li>
			<li>Previous</li>
			 }else{ 
			<li>@Html.ActionLink("First", "Index")</li>
			<li>@Html.ActionLink("Previous", "Index", new { index = Model.Users.PageIndex - 1 })</li>
			 } 

			<li>Page @Model.Users.PageNumber of @Model.Users.PageCount</li>

			@if (Model.Users.IsLastPage){ 
			<li>Next</li>
			<li>Last</li>
			 }else{ 
			<li>@Html.ActionLink("Next", "Index", new { index = Model.Users.PageIndex + 1 })</li>
			<li>@Html.ActionLink("Last", "Index", new { index = Model.Users.PageCount - 1 })</li>
             } 
		</ul>
        <div class="clear"></div>
	 }else{ 
		<p>Ни одного пользователя не зарегистрировано.</p>
	 } 
	</div>

	<h3>Роли</h3>
	<div class="mvcMembership-allRoles">
	@if(Model.Roles.Count() > 0 ){ 
		<ul type="none">
			@foreach(var role in Model.Roles){ 
			<li>
				
				@using(Html.BeginForm("DeleteRole", "UserAdministration", new{id=role})){ 
		            @Html.ActionLink(role, "Role", new { id = role }, new { style = "width: 140px; display: inline-block;" })		
                    <input type="submit" value=" " class="delete" />
    } 
			</li>
   } 
		</ul>
 }
 else
 { 
		<p>Ни одной роли не создано.</p>
 } 
	@using (Html.BeginForm("CreateRole", "UserAdministration"))
 { 
		<fieldset>
			<label for="id">Роль:</label>
			@Html.TextBox("id")
			<input type="submit" value="Создать роль" />
		</fieldset>
	 } 
	</div>


